package com.qf.qfwemedia.controller.v1;

import com.qf.qfleadnewsmodel.commons.dtos.PageResponseResult;
import com.qf.qfleadnewsmodel.commons.dtos.ResponseResult;
import com.qf.qfleadnewsmodel.enums.AppHttpCodeEnum;
import com.qf.qfleadnewsmodel.wemedia.dtos.MaterialPageDto;
import com.qf.qfwemedia.service.WmMaterialService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/api/v1/material")
public class MaterialController {

    @Autowired
    private WmMaterialService wmMaterialService;

    /**
     * 分页查询素材信息
     * @return
     */
    @PostMapping("/list")
    public PageResponseResult list(@RequestBody MaterialPageDto materialPageDto){

        return wmMaterialService.pageByCollection(materialPageDto);
    }

    @PostMapping("/upload_picture")
    public ResponseResult upload_pic(MultipartFile multipartFile) throws Exception {
        if (multipartFile != null){
            return wmMaterialService.uploadPic(multipartFile);
        }

        return ResponseResult.errorResult(AppHttpCodeEnum.PARAM_INVALID);
    }
}
